#!/bin/sh

mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs udev /dev
mkdir /dev/pts
mount -n -t devpts -o gid=5,mode=620 none /dev/pts
udevd --daemon
udevadm trigger
udevadm settle
chmod a+rx /
modprobe loop

ulimit -n 999999

ifconfig lo up
dhclient -v eth0
dhclient -v eth1

mkdir /var/run/sshd
/usr/sbin/sshd

PARENT=`awk 'BEGIN {RS = " "} ; {split($1,a,"="); if (a[1] == "parent") {print a[2]; }}' /proc/cmdline`
PORT=`awk 'BEGIN {RS = " "} ; {split($1,a,"="); if (a[1] == "port") {print a[2]; }}' /proc/cmdline`

# get and launch miniccc as a client
wget http://${PARENT}:${PORT}/files/miniccc
chmod a+x /miniccc
/miniccc -parent $PARENT -port $PORT -logfile /miniccc.log &

setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'
